package com.zbf4.intercepter;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/5/21  9:38
 * 描述:
 */
@Component
public class TestInterceptor extends HandlerInterceptorAdapter {

    /**
     * 作者: LCG
     * 日期: 2021/5/21  9:46
     * 描述: 处理程序执行之前 运行
     * @Param [request, response, handler]
     * @Return boolean
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("======preHandle=======");

        return super.preHandle(request, response, handler);
    }

    /**
     * 作者: LCG
     * 日期: 2021/5/21  9:47
     * 描述: 处理程序运行之后，视图渲染之前运行
     * @Param [request, response, handler, modelAndView]
     * @Return void
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

        System.out.println("======postHandle=======");

        super.postHandle(request, response, handler, modelAndView);
    }

    /**
     * 作者: LCG
     * 日期: 2021/5/21  9:47
     * 描述: 视图渲染成功以后 运行
     * @Param [request, response, handler, ex]
     * @Return void
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

        System.out.println("======afterCompletion=======");

        super.afterCompletion(request, response, handler, ex);
    }

    /**
     * 作者: LCG
     * 日期: 2021/5/21  9:48
     * 描述: HandlerInterceptor还可以实现AsyncHandlerInterceptor以执行afterConcurrentHandlingStarted回调，这就是所谓的代替postHandle和afterCompletion处理开始异步时。
     * @Param [request, response, handler]
     * @Return void
     */
    @Override
    public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("======afterConcurrentHandlingStarted=======");

        super.afterConcurrentHandlingStarted(request, response, handler);
    }
}
